package part7;

/**
 * @author wcj
 * @Date 2021/5/15 15:29
 * @Version 1.0
 */
public class Part76 extends Shape{
    private Circle circle;
    private Triangle triangle;

    public Part76(int i){
        super(i);
        circle = new Circle(i);
        triangle = new Triangle(i);
    }

    @Override
    public void dispose(){
        System.out.println("Part76 dispose");
        circle.dispose();
        triangle.dispose();
        super.dispose();
    }

    public static void main(String[] args) {
        Part76 part76 = new Part76(1);
        // try-catch-finally，finally通常用来执行一些必须要做的
        try{
            // TODO
        }finally {
            part76.dispose();
        }
    }
}

class Shape{
    public Shape(int i){
        System.out.println("shape");
    }
    public void dispose(){
        System.out.println("shape dispose");
    }
}

class Circle extends Shape{
    public Circle(int i){
        super(i);
        System.out.println("Circle");
    }
    @Override
    public void dispose(){
        System.out.println("circle dispose");
        super.dispose();
    }
}

class Triangle extends Shape{
    public Triangle(int i){
        super(i);
        System.out.println("triangle");
    }
    @Override
    public void dispose(){
        System.out.println("triangle dispose");
        super.dispose();
    }
}
